package com.foreknow.elm.controller;

import com.foreknow.elm.po.Orders;
import com.foreknow.elm.service.Impl.OrdersServiceImpl;
import com.foreknow.elm.service.OrdersService;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

public class OrdersController {
    public Object createOrders(HttpServletRequest request){
        //获取请求参数  /OrdersController/createOrders?userId=1234563212&businessId=10001&daId=17&orderTotal=125
        String userId = request.getParameter("userId");
        Integer businessId = Integer.parseInt(request.getParameter("businessId"));
        Integer daId = Integer.parseInt(request.getParameter("daId"));
        Double orderTotal = Double.parseDouble(request.getParameter("orderTotal"));
        OrdersService ordersService = new OrdersServiceImpl();
        int orderId = ordersService.createOrders(userId,businessId,daId,orderTotal);
        return orderId;
    }

    public Object getOrdersById(HttpServletRequest request){
        //获取请求参数  /OrdersController/getOrdersById?orderId=22
        Integer orderId = Integer.parseInt(request.getParameter("orderId"));
        OrdersService ordersService = new OrdersServiceImpl();
        Orders orders = ordersService.getOrdersById(orderId);
        return orders;
    }

    public Object listOrdersByUserId(HttpServletRequest request){
        //获取请求参数  /OrdersController/listOrdersByUserId?userId=1234563212
        String userId = request.getParameter("userId");
        OrdersService ordersService = new OrdersServiceImpl();
        List<Orders> list = new ArrayList<>();
        list = ordersService.listOrdersByUserId(userId);
        return list;
    }

}